#!/bin/bash

exec_sql_file() {
    local file=${cmd##*source}
    file=${file/\//}
    rds -w / -n mysql-master "$@" <<< "source $file"
}

parse_stdin() {
    read cmd
    test "${cmd##*source}" != "$cmd"    \
            && exec_sql_file "$@"       \
            || rds -n mysql-master "$@" <<< "$cmd"
}

read -t 0 && parse_stdin "$@" || rds -n mysql-master "$@"

